package {
	
	import flash.utils.getTimer;
	import org.flixel.FlxGroup;
	import org.flixel.FlxObject;

	public class EnemyManager extends FlxGroup
	{
		private var lastReleased:int;
		private var releaseRate:uint = 600;
		private var enemyType:Class;
		
		public function EnemyManager(EnemyClass:Class){
			super();
			enemyType = EnemyClass;
			for (var i:int = 0; i < 30; i++)
			{
				add(new EnemyClass);
			}
		}

		public function release():void{
			var alienBasic:AlienBasic = enemyType(getFirstAvailable());

			if (alienBasic)
			{
				alienBasic.spawn();
			}
		}
		
		public function shotHitEnemy(shot:FlxObject, enemy:FlxObject):void {
			shot.kill();
			enemy.hurt(1);
		}

		public function enemyHitPlayer(shot:FlxObject, enemy:FlxObject):void {
			shot.kill();
			Registry.player.hurt(2);
		}
		
		override public function update():void{
			super.update();
			if (getTimer() > lastReleased + releaseRate)
			{
				lastReleased = getTimer();
				release();
			}
		}
		
		public function setReleaseRate(rate:uint):void {
			releaseRate = rate;
		}
	}
}